package com.ktgj.customer.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ktgj.common.log.annotation.Log;
import com.ktgj.common.log.enums.BusinessType;
import com.ktgj.common.security.annotation.PreAuthorize;
import com.ktgj.customer.domain.Customeraccount;
import com.ktgj.customer.service.ICustomeraccountService;
import com.ktgj.common.core.web.controller.BaseController;
import com.ktgj.common.core.web.domain.AjaxResult;
import com.ktgj.common.core.utils.poi.ExcelUtil;
import com.ktgj.common.core.web.page.TableDataInfo;

/**
 * 会员账号Controller
 * 
 * @author ruoyi
 * @date 2022-01-04
 */
@RestController
@RequestMapping("/customeraccount")
public class CustomeraccountController extends BaseController
{
    @Autowired
    private ICustomeraccountService customeraccountService;

    /**
     * 查询会员账号列表
     */
    //@PreAuthorize(hasPermi = "customer:customeraccount:list")
    @GetMapping("/list")
    public TableDataInfo list(Customeraccount customeraccount)
    {
        startPage();
        List<Customeraccount> list = customeraccountService.selectCustomeraccountList(customeraccount);
        return getDataTable(list);
    }

    /**
     * 导出会员账号列表
     */
    //@PreAuthorize(hasPermi = "customer:customeraccount:export")
    @Log(title = "会员账号", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Customeraccount customeraccount) throws IOException
    {
        List<Customeraccount> list = customeraccountService.selectCustomeraccountList(customeraccount);
        ExcelUtil<Customeraccount> util = new ExcelUtil<Customeraccount>(Customeraccount.class);
        util.exportExcel(response, list, "会员账号数据");
    }

    /**
     * 获取会员账号详细信息
     */
    //@PreAuthorize(hasPermi = "customer:customeraccount:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(customeraccountService.selectCustomeraccountById(id));
    }

    /**
     * 新增会员账号
     */
    //@PreAuthorize(hasPermi = "customer:customeraccount:add")
    @Log(title = "会员账号", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Customeraccount customeraccount)
    {
        return toAjax(customeraccountService.insertCustomeraccount(customeraccount));
    }

    /**
     * 新增会员账号
     * @param customeraccount
     * @return
     */
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody Customeraccount customeraccount)
    {
        return toAjax(customeraccountService.insertCustomeraccount(customeraccount));
    }

    /**
     * 修改会员账号
     */
    //@PreAuthorize(hasPermi = "customer:customeraccount:edit")
    @Log(title = "会员账号", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Customeraccount customeraccount)
    {
        return toAjax(customeraccountService.updateCustomeraccount(customeraccount));
    }

    /**
     * 修改会员12306密码
     * @param customeraccount
     * @return
     */
    @PostMapping("/updateAccountPassword")
    public AjaxResult updateAccountPassword(@RequestBody Customeraccount customeraccount)
    {
        return toAjax(customeraccountService.updateCustomeraccountByCustomerId(customeraccount));
    }

    /**
     * 删除会员账号
     */
    //@PreAuthorize(hasPermi = "customer:customeraccount:remove")
    @Log(title = "会员账号", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(customeraccountService.deleteCustomeraccountByIds(ids));
    }

    @PostMapping("/queryAccountIdAndAccountPassword")
    public AjaxResult queryAccountIdAndAccountPassword(@RequestParam("customerId") Long customerId, @RequestParam("accountType") String accountType) {
        return AjaxResult.success(customeraccountService.queryAccountIdAndAccountPassword(customerId, accountType));
    }
}
